<?php
/**
 * User: shutao
 * @var View $this
 */

use wechat\services\WeSystemVar;
use yii\web\View;

$this->title = '系统变量';
$data = WeSystemVar::vars();
$hasBtn = \ttcommon\base\Data::hasValue($_GET, 'btn', false);
?>
<div>
    <div class="xblock">
        <span class="x-right">共有数据：<span><?php echo count($data) ?></span> 条</span>
    </div>

    <table class="layui-table">
        <tr>
            <th>变量名</th>
            <th>说明</th>
            <th>值示例</th>
            <th>来源</th>
            <?php if ($hasBtn) { ?>
                <th>选择</th>
            <?php } ?>
            <th></th>
        </tr>

        <?php foreach ($data as $name => $var) {
            ?>
            <tr>
                <td><?php echo $name ?></td>
                <td><?php echo $var[0] ?></td>
                <td><?php echo $var[1] ?></td>
                <td><?php echo \ttcommon\base\Data::hasValue($var, 2, '') ?></td>
                <?php if ($hasBtn) { ?>
                    <td>
                        <a onclick="selectVar('<?php echo $name ?>','<?php echo urlencode($var[1]) ?>')"
                           class="layui-btn layui-btn-xs layui-btn-normal">
                            <i class="layui-icon">&#xe605;</i>
                        </a>
                    </td>
                <?php } ?>
                <td></td>
            </tr>
            <?php
        } ?>
    </table>
</div>
<?php if ($hasBtn) { ?>
    <script>
        function selectVar(name, title) {
            xlayer.close({
                name: name, title: decodeURI(title)
            });
        }
    </script>

<?php } ?>
